package com.graduate.front.handle;

import com.graduate.common.entity.Result;
import com.graduate.common.exception.UserException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局的异常处理
 * @author bwzfy
 * @create 2021/5/11
 **/
@ControllerAdvice
public class GlobalExceptionHandle {

    @ResponseBody
    @ExceptionHandler(UserException.class)
    public Result<String> userException(UserException e) {
        System.out.println("捕获到了异常");
        e.printStackTrace();
        Result<String> result = new Result<>();
        result.setCode(510);
        result.setData("err");
        return result;
    }

}
